package org.yinxian.payment.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yinxian.payment.entities.CommonResult;
import org.yinxian.payment.entities.Payment;
import org.yinxian.payment.service.PaymentService;

@Slf4j
@RequestMapping("/payment")
@RestController
public class PaymentController {

    @Autowired
    private PaymentService paymentService;



    @PostMapping("/create")
    public CommonResult<?> create(@RequestBody Payment payment){

        int result = paymentService.create(payment);
        log.info("插入结果：{}",result);
        if (  result > 0 ) return new CommonResult<>(200,"Success");
        return  new CommonResult<>(444,"Fail");
    }

    @GetMapping("/fetch/{id}")
    public  CommonResult<?> getOne(@PathVariable("id") Long id){

        Payment payment = paymentService.getPaymentById(id);
        if( null == payment) new CommonResult<>(444, String.format("ID为%s,没有找到相关记录",id));
        System.out.println("11122sss1");
        return new CommonResult<>(200,"Success",payment);
    }

}
